using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAL;
using Utility;

namespace BUS
{
    public class LOAIHANG_BUS
    {
        public static void insert(LoaiHang_DTO loaihang)
        {
            LOAIHANG_DAL loaihangdal = new LOAIHANG_DAL();
            loaihangdal.insert(loaihang);
        }
        public static void update(LoaiHang_DTO loaihang)
        {
            LOAIHANG_DAL loaihangdal = new LOAIHANG_DAL();
            loaihangdal.update(loaihang);
        }
        public static void delete(int mloaihang)
        {
            LOAIHANG_DAL loaihangdal = new LOAIHANG_DAL();
            loaihangdal.delete(mloaihang);
        }
        public static LoaiHangColection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            LOAIHANG_DAL loaihangdal = new LOAIHANG_DAL();
            return loaihangdal.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        //public static LoaiHangColection GetAll()
        //{
        //    int total = 0;
        //    Criteria cri = new Criteria();
        //    LOAIHANG_DAL loaihangdal = new LOAIHANG_DAL();
        //    return loaihangdal.Get(cri.Criter, 0, 0, LOAIHANGCOLUMNS.MaLoai.ToString(), OrderDirection.ASC.ToString(), out total);
        //}
        public static LoaiHangColection GetAll()
        {
            int total = 0;
            LOAIHANG_DAL loaihangdal = new LOAIHANG_DAL();
            return loaihangdal.Get("where 1=1", 0, 0, LOAIHANGCOLUMNS.MaLoai.ToString(), "ASC", out total);
        }
        public static LoaiHang_DTO GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, LOAIHANGCOLUMNS.MaLoai.ToString(), Condition.EQUAL, iD);
            LOAIHANG_DAL lhangdal = new LOAIHANG_DAL();
           LoaiHangColection lhangcltion = lhangdal.Get(cri.Criter, 0, 0, LOAIHANGCOLUMNS.MaLoai.ToString(), OrderDirection.ASC.ToString(), out total);
            if (lhangcltion.Count > 0)
                return lhangcltion[0];
            return null;

        }
    }
}
